package com.socket.socket.demos.socket;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.net.ServerSocket;

@Configuration
public class SocketServerConfig {

    private static final int SERVER_PORT = 7888;

    @Bean
    public ServerSocket serverSocket() {
        try {
            ServerSocket serverSocket = new ServerSocket(SERVER_PORT);
            serverSocket.setReuseAddress(true); // 启用端口复用
            return serverSocket;
        } catch (IOException e) {
            throw new RuntimeException("Failed to create ServerSocket on port " + SERVER_PORT, e);
        }
    }
}
